package simpleGui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;

import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;

public class GuiComponent implements MouseListener,MouseMotionListener {
		public ArrayList<GuiComponent>children=new ArrayList<GuiComponent>();
		int x, y, w, h;
		String label;
		boolean displayLabel;
		final static int TOP=0;
		final static int BOTTOM=1;
		final static int LEFT=2;
		final static int RIGHT=3;
		
		Gui gui;
		public GuiComponent(){
		}
		
		
		public void addComponent(GuiComponent comp){
			children.add(comp);
		}
		
		public void unregister(){
			gui.children.remove(this);
			gui.parent.removeMouseListener(this);
			gui.parent.removeMouseMotionListener(this);
		}
		
		public GuiComponent(Gui gui,int x,int y,int w,int h){
			this.gui=gui;
			gui.parent.addMouseListener(this);
			gui.parent.addMouseMotionListener(this);
			gui.children.add(this);
			setDimensions(x,y,w,h);
		}
		
		public GuiComponent(Gui gui,int x,int y,int w,int h, String label){
			this(gui,x,y,w,h);
			this.label=label;
		}
		void setDimensions(int x,int y,int w,int h){
			this.x=x;
			this.y=y;
			this.w=w;
			this.h=h;
		}
		
		public void display(PGraphics g){
			g.pushStyle();
			g.strokeWeight(gui.getStrokeWeight());
			g.fill(gui.getFillColor());
			g.stroke(255);
			g.rectMode(PGraphics.CORNER);
			g.rect(x,y,w,h);
			g.popStyle();
			displayChildren(g);
		}
		public void displayChildren(PGraphics g){
			for (int i=0;i<children.size();i++){
				children.get(i).display(g);
				
			}
		}
		public boolean contains(int cx,int cy){
			if (cx>x&&cx<x+w&&cy>y&&cy<y+h)return true;
			return false;
		}
		@Override
		public void mouseClicked(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mouseEntered(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mouseExited(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mousePressed(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mouseReleased(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mouseDragged(MouseEvent arg0) {
			// TODO Auto-generated method stub
			
		}
		@Override
		public void mouseMoved(MouseEvent arg0) {
			// TODO Auto-generated method stub
		}
		public String getLabel() {
			return label;
		}
		public void setLabel(String label) {
			this.label = label;
		}
		public boolean isDisplayLabel() {
			return displayLabel;
		}
		public void setDisplayLabel(boolean displayLabel) {
			this.displayLabel = displayLabel;
		}
}
